﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lessson18_练习题
{
    #region
    //写一个动物抽象类  写三个子类
    //人叫 狗叫 猫叫   你好 ，旺旺 ，喵喵 
   
    abstract class Animal
    {
        public abstract void Speak();
    }
     class People:Animal
     {
        public override void Speak()
        {
            Console.WriteLine("你好");
        }
     }  class Dog:Animal
     {
        public override void Speak()
        {
            Console.WriteLine("汪汪");
        }
     }  class Cat:Animal
     {
        public override void Speak()
        {
            Console.WriteLine("喵喵");
        }
     }
    #endregion
    #region  
    //创建一个图形类，要求面积和周长两个方法
    //创建一个矩形类，正方形类，圆形类继承图形类
    //实例化矩形，正方形，图形对象求面积和周长
    abstract class Graph
    {
        public abstract float Area();
        public abstract float Zhouchang();   
    }
    class Rectangle : Graph
    {
        private float height;
        private float width;    

        public  Rectangle(float height , float width)  //构造函数 与类名相同
        {
            this.width = width;
            this.height = height;
        }
        public override float Area()
        {
            return height * width;  
        }
        public override float Zhouchang()
        {
            return 2*(width + height);
        }
    }
    class Square:Graph
    {
        private float edge;
        public  Square(float edge)
        {
            this.edge = edge;
        }



        public override float Area()
        {
            return edge * edge;
        }
        public override float Zhouchang()
        {
            return 4 * edge;
        } 
    }

    class Round : Graph
    {
       
        private float  r;
        public  Round(float r)
        {

            this.r = r;
        }




        public override float Area()
        {
            return 3.14f * r * r ;
        }
        public override float Zhouchang()
        {
            return 2 * 3.14f * r;
        }
    }
    
    #endregion
    internal class Program
    {

    

        static void Main(string[] args)
        {
            #region 动物抽象类
            //Console.WriteLine("抽象类练习题");
            //Animal p = new People();
            //p.Speak();

            //Animal d = new Dog();
            //d.Speak();  

            //Animal c = new Cat();   
            //c.Speak();
            #endregion

            #region 图像抽象类
            Graph rac = new Rectangle(3,5);
            Console.WriteLine(rac.Area());
            Console.WriteLine(rac.Zhouchang());

            Graph square = new Square(5);
            Console.WriteLine(square.Area());
            Console.WriteLine(square.Zhouchang());

            Graph round = new Round(5);
            Console.WriteLine(round.Area());
            Console.WriteLine(round.Zhouchang());
            #endregion
        }
    }
}
